import java.util.Scanner;
public class Task14 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("Enter number of contestants: ");
		int numberOfContestants = sc.nextInt();
		int [] result = new int[numberOfContestants];
		int [] weight = new int[numberOfContestants]; 
		
		
		for(int i=0;i<numberOfContestants;i++){
			System.out.print("Enter contestant N" + (i+1) + "'s result: ");
			result[i] = sc.nextInt();
			System.out.print("Enter contestant N" + (i+1) + "'s weight: ");
			weight[i] = sc.nextInt();
		}
		int currentWinner = 0;
		int currentMaxResult = result[0];
		
		for (int i=0;i<numberOfContestants;i++){
			
			if(currentMaxResult < result[i]){
				currentWinner = i;
				currentMaxResult = result[i];
			}else {
			
				if(currentMaxResult == result[i]){
					if(weight[currentWinner] > weight[i]){
						currentWinner = i;
					}
				}
			}
		}
		System.out.println("The winner is: Contestant N" + (currentWinner + 1));
		sc.close();
		
	}

}
